package com.example.sampleworks.ui;


import com.example.sampleworks.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListViewAndroidEx extends Activity{
	ListView listView;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_view);
		
		listView = (ListView)findViewById(R.id.listView1);
		
	
	String[] values = new String[] {"Android List View",
			"Adapter implementation",
			"Simple List View in Android",
			"Create List View Android",
			"Android Example",
			"List View Source Code",
			"List View Array Adapter",
			"Android Example List View"};
	
	ArrayAdapter<String>adapter = new ArrayAdapter<String>(this,
			R.layout.list1,R.id.textView2,values);
	
	listView.setAdapter(adapter);
	
	listView.setOnItemClickListener(new OnItemClickListener(){
		
		
		@Override
		public void onItemClick(AdapterView<?> parent, View view,int position,long id){
			
			int itemPosition = position;
			
			String itemValue = (String) listView.getItemAtPosition(position);
			Toast.makeText(getApplicationContext(), "Position :"+itemPosition+"ListItem:"+itemValue, Toast.LENGTH_LONG).show();
		}
	});
	

		
			
		
	}

}
